package com.yunyouyi.grabtickets.controller;

import com.yunyouyi.grabtickets.service.TicketService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ticket")
public class TicketController {

    @Resource
    private TicketService ticketService;

    @PostMapping("/buy")
    public String buy(@RequestParam String trainId) {
        boolean success = ticketService.buy(trainId);
        return success ? "购票成功" : "购票失败，可能已售空";
    }
}